﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace 西南财经大学学术讲座信息获取小工具
{
    class WebHelper
    {
        public static string GetHtmlCodeByWebClient(string url, string encoding)
        {
            string strWebData;
            using (WebClient wc = new WebClient())
            {
                wc.Credentials = CredentialCache.DefaultCredentials;
                byte[] dataBuffer = wc.DownloadData(url);
                strWebData = Encoding.Default.GetString(dataBuffer);
                strWebData = Encoding.GetEncoding(encoding).GetString(dataBuffer);
                wc.Dispose();
            }
            return strWebData;
        }

        public static bool isClientWeb()
        {
            try
            {
                using (WebClient wc = new WebClient())
                {
                    wc.DownloadData("http://www.swufe.edu.cn");
                    wc.Dispose();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
